<?php
/*
 * @Descripttion: 
 * @version: 1.0
 * @Author: Sam
 * date: 2021-09-23 10:31:13
 * @LastEditors: Sam
 * @LastEditTime: 2021-12-08 20:53:37
 */

namespace app\admin\model;

class StoreCouponIssueUser extends BaseModel
{
    /**
     * 模型名称
     * @var string
     */
    protected $name = 'store_coupon_issue_user'; //优惠券领取记录


    public static function systemCouponIssuePage($issue_coupon_id)
    {
        $model = self::alias('A')->field('B.nickname,B.avatar,A.add_time')
            ->join('user B', 'A.uid = B.uid')
            ->where('A.issue_coupon_id', $issue_coupon_id);
        return self::page($model, function ($item) {
            $item['add_time'] = $item['add_time'] == 0 ? '未知' : date('Y/m/d H:i', $item['add_time']);
            return $item;
        }, ['id' => $issue_coupon_id]);
    }

    public function user(){
        return $this->belongsTo('user','uid')->bind(['nickname','avatar']);
    }

    public static function addUserIssue($uid,$issue_coupon_id)
    {
        $add_time = time();
        return self::create(compact('uid','issue_coupon_id','add_time'));
    }

}